package org.seefly.iprint.entity;

import lombok.Data;

import java.math.BigDecimal;

@Data
public class OrderItem implements Cloneable{
    private Integer id;
    /**订单id*/
    private Integer orderId;
    /**购买数量*/
    private String count;
    /**商品标题 */
    private String title;
    /**文件地址*/
    private String fileAddr;
    /**文件名称*/
    private String fileName;
    /**单价=pageCount X pagePrice + 增值*/
    private BigDecimal unitPrice;
    /**总额，冗余字段。 单价乘数量*/
    private BigDecimal total;
    /**纸张类型 黑白、彩色*/
    private String pageType;
    /**纸张尺寸 A3\A4\4寸、5寸...*/
    private String pageSize;
    /**单双面*/
    private String singleDouble;
    /**页面数量*/
    private String pageCount = "1";
    /**纸价*/
    private BigDecimal pagePrice;
    /**打印类型*/
    private String printType;
    /**边距*/
    private String margin;
    /**工艺 装订方式*/
    private String craftwork;
    /**背景色*/
    private String changeBgc;
    /**纸张重量*/
    private String pageWeight;



    public BigDecimal getUnitPrice() {
        //文档单位价格=页数X每页价格+增值服务
        //其他=每页价格+增值服务
        //所以令页数默认为1 则可使上述两种方式相等
        return this.pagePrice.multiply(new BigDecimal(this.pageCount)).add(this.unitPrice);
    }

    public BigDecimal getTotal() {
        //总额=数量X单价
        return getUnitPrice().multiply(new BigDecimal(this.getCount()));
    }

    
    @Override
    public Object clone() throws CloneNotSupportedException {
        OrderItem oi = (OrderItem) super.clone();
        if(this.unitPrice != null) {
            oi.setUnitPrice(new BigDecimal(this.unitPrice.toString()));
        }
        if(this.pagePrice != null) {
            oi.setPagePrice(new BigDecimal(this.pagePrice.toString()));
        }
        if(this.total != null) {
            oi.setTotal(new BigDecimal(this.total.toString()));
        }
        return oi;
    }

    @Override
    public String toString() {
        return "OrderItem [id=" + id + ", orderId=" + orderId + ", count=" + count + ", title=" + title + ", fileAddr="
                + fileAddr + ", fileName=" + fileName + ", unitPrice=" + unitPrice + ", total=" + total + ", pageType="
                + pageType + ", pageSize=" + pageSize + ", singleDouble=" + singleDouble + ", pageCount=" + pageCount
                + ", pagePrice=" + pagePrice + ", printType=" + printType + ", margin=" + margin + ", craftwork="
                + craftwork + ", changeBgc=" + changeBgc + ", pageWeight=" + pageWeight + "]";
    } 
    
    
}